package com.stadium.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.stadium.common.utils.SqlMapper;
import com.stadium.common.utils.UserUtils;
import com.stadium.dto.SysAgreementDto;
import com.stadium.entity.SysAgreement;
import com.stadium.mapper.SysAgreementMP;
import com.stadium.service.SysAgreementSV;
import com.stadium.vo.SysAgreementVo;
import com.stadium.vo.searchVo.SysAgreementSearchVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SysAgreementSVI implements SysAgreementSV {
    @Autowired
    private SysAgreementMP mapper;
    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<SysAgreement> queryBySQL(String sql, Map<String, Object> map) {
        return sqlMapper.selectList(sql, map, SysAgreement.class);
    }

    @Override
    public void save(SysAgreementVo sysAgreementVo) {
        SysAgreement sysAgreement = new SysAgreement();
        BeanUtils.copyProperties(sysAgreementVo, sysAgreement);
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        sysAgreement.setCreateUser(UserUtils.getUserId());
        sysAgreement.setUpdateUser(UserUtils.getUserId());
        sysAgreement.setId(id);
        mapper.save(sysAgreement);
    }

    @Override
    public void update(SysAgreementVo sysAgreementVo) {
        SysAgreement sysAgreement = new SysAgreement();
        BeanUtils.copyProperties(sysAgreementVo, sysAgreement);
        sysAgreement.setUpdateUser(UserUtils.getUserId());
        mapper.update(sysAgreement);
    }

    @Override
    public void saveBatch(List<SysAgreement> list) {
        mapper.saveBatch(list);
    }

    @Override
    public void delete(String id) {
        mapper.delete(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        mapper.deleteBatch(ids);
    }

    @Override
    public List<SysAgreementDto> query(SysAgreementSearchVo searchVo) {
        return mapper.query(searchVo);
    }

    @Override
    public SysAgreementDto get() {
        return mapper.get();
    }

    @Override
    public int getCount(SysAgreementSearchVo searchVo) {
        return mapper.getCount(searchVo);
    }

}
